
var Table = {
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'core.php?do=Table.edit&id=' + id + p2;
		var c2 = 'core.php?do=Table.view&id=' + id;

		var c3 = 'core.php?do=Table.add&id=' + id;
		var c4 = 'core.php?do=Table.status&id=' + id;
		
		var a1 = ['编辑信息', 'url', 'Table.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '600x400'];

		// 正常
		if (status == 1) {
			var s = c1 + ", " + c2;

			return this.popup_(e, [a1, a2], s);
		}

		var s = c1 + ", " + c2;

		return this.popup_(e, [a1, a2], s);
	},

	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var ss = 'core.php?do=Table.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Table.dialog_ss', '400x200'];
		
		s += ", " + ss;
		a.push(bb);
		
		return popup(e, a, s);
	}, 

	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('core.php?do=Table.audit&item=88', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'core.php?do=Table.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	}, 

	/**
	 * 编辑
	 */
	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				body.id = form.id.value;
				body.code = form.code.value;
				body.name = form.name.value;
				body.buydate = form.buydate.value;

				body.supplier = form.supplier.value;				
				body.supplier_x = Supplier.supplier_x(form);

				body.park = form.park.value;
				body.content = form.content.value;
				
				body.emp = form.emp.value;

				$(this).dialog("close");

				var url = 'core.php?do=Table.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	dialog_update_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"更新": function() {
				if (!confirm("确认是否更新？")) {
					return false;
				}
				
				var form = $("#form_edit")[0];

				var body = { };
				body.table = form.table.value;
				
				body.emp_from = form.emp_from.value;
				body.emp_to = form.emp_to.value;
				
				body.status = form.status.value;
				
				body.createtime1 = form.createtime1.value;
				body.createtime2 = form.createtime2.value;
				body.modifytime1 = form.modifytime1.value;
				body.modifytime2 = form.modifytime2.value;
				
				$(this).dialog("close");

				$.post('core.php?do=Table.updatePost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	}

};
